#include <iostream>

#include "gobang.h"

using namespace std;

int main(int argc, char const *argv[])
{   
    int ret = 0;
    /**
     * flag 是一个游戏胜利判断条件
     */
    int flag = 0;
    /**
     * 记录当前落子的总个数，同时可以利用 % 2 判断
     * 落子的玩家是哪一个玩家
     */
    int count = 0;
    int row_index = 0;
    int col_index = 0;
    char player = '\0';
    char chess_board[ROW][COL] = {'\0'};

    gobang_ui_init(chess_board);

    while (1)
    {
        show_chess_board(chess_board);

        if (count % 2 == 0)
        {
            cout << "执黑落子";
            player = BLACK;
        }
        else
        {
            cout << "执白落子";
            player = WHITE;
        }

        cout << "，请输入对应的下标位置, 例如 : 2 3 : ";
        cin >> row_index >> col_index;

        ret = place_stone(chess_board, row_index, col_index, player);

        if (ret)
        {
            flag = is_win(chess_board, row_index, col_index, player);
            cout << "flag = " << flag << endl;
        }

        count += ret;

        if (flag)
        {
            cout << (player == BLACK ? "执黑获胜" : "执白获胜") << endl;
            break;
        }

    }
    return 0;
}
